package geektime.spring.springbucks.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.hibernate.annotations.Columns;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.boot.model.relational.Namespace.Name;
import org.joda.money.Money;

@Entity
@Table(name="T_COFFEE")
@Builder
@Data
@ToString(callSuper =true )
@NoArgsConstructor
@AllArgsConstructor
public class Coffee extends BaseEntity {

  private static final long serialVersionUID = 4621746096807173742L;
  private  String name;
  @Type(type ="org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmount" ,parameters = {
      @Parameter(name = "currencyCode",value = "CNY")})
  private Money price;

//  Based on http://jadira.sourceforge.net 货币类型通常由货币和金额组成。 Jadira可以使用参数配置的货币仅将数量存储到数据库中。例如：
//
//  @Column
//  @Type(type = "org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmount",
//      parameters = {@org.hibernate.annotations.Parameter(name = "currencyCode", value = "USD")})
//  private Money money;
//  Alternatively, with other types two columns to hold the amount an currency:
//  @Columns(columns = { @Column(name = "MY_CURRENCY"), @Column(name = "MY_AMOUNT") })
//  @Type(type = "org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmountAndCurrency")
//  private Money money;
}
